package com.spring.design.proxy;

/**
 * 代理模式  Spring AOP 切面用了Cglib代理方式
 */
public class Client {

	public static void main(String[] args) {
		//创建目标对象
		ITeacherDao target = new TeacherDao();
		
		//给目标对象创建代理对象 ITeacherDao
		ITeacherDao proxyInstance = (ITeacherDao)new ProxyFactory(target).getProxyInstance();
	
		// proxyInstance=class com.sun.proxy.$Proxy0 内存中动态生成了代理对象
		System.out.println("proxyInstance=" + proxyInstance.getClass());
		
		//通过代理对象调用目标对象的方法
		proxyInstance.teach();
		
		proxyInstance.sayHello(" tom ");

		//-----------------------------------------------------------
		//Cglib代理开始
		//创建目标对象
		TeacherDao2 targe = new TeacherDao2();
		//将目标对象传给代理对象
		TeacherDao2 proxyInstance1 = (TeacherDao2)new ProxyFactory2(targe).getProxyInstance();

		proxyInstance1.teach();
	}

}
